USE [WarehouseManagement]
GO

/****** Object:  StoredProcedure [dbo].[GetSingleProduct]    Script Date: 03/15/2011 00:37:43 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		duylv00360
-- Create date: 3/14/2011
-- Description:	This stored procedure use to get specific product
-- =============================================
ALTER PROCEDURE [dbo].[GetSingleProduct] 
	-- Add the parameters for the stored procedure here
	@productID int = 0
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT
		[ProductID]
		, [ProductCode]
		, [ProductName]
		, [Description]
		, [isDelete]
	FROM 
		[Product]
	WHERE 
		[ProductID] = @productID
	
	SELECT 
		m.[MaterialID]
		, m.[MaterialCode]
		, m.[MaterialName]
		, m.[Description]
		, m.[IsDelete]
		, bs.[MaterialQuantity] AS Quantity
	FROM 
		Material m
	INNER JOIN
		BuiltupStructure bs
	ON
		bs.ProductID = @ProductID AND m.MaterialID = bs.MaterialID

END

GO
/*
use WarehouseManagement
go
exec [GetSingleProduct] @ProductID=1
*/